home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!austern
- From: "Nathan Myers <http://www.cantrip.org/>" <ncm@cantrip.org>
- Newsgroups: comp.std.c++
- Subject: Re: Better template syntax?
- Date: 17 Apr 1996 10:41:31 PDT
- Organization: Best Internet Communications
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <31747848.714640D9@cantrip.org>
- References: <31741E6C.53CA@cs.tu-berlin.de>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: Tue, 16 Apr 1996 21:49:12 -0700
- X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i386)
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMXUtTUy4NqrwXLNJAQHmxgIAkdvEShLBXsvfDnioe/sZ7yJEuOi39Uex
- jWWaAU4PLM/zJ7XZqRNVZJ5o5Ueg0OX/D+1UpH3Xfwx9p88drIQMLA==
- =EUPK
- Originator: austern@isolde.mti.sgi.com
-
- Roman Lechtchinsky wrote:
-
- > ... when declaring templates, why isn't it required to declare what
- > one expects of the template's parameters?
- > ... has [this] been considered and rejected ( and why ) ?
-
- [This is from a paper by Koenig and Stroustrup, "Foundations for
- Native C++ Styles" that appeared in Software Practice and Experience
- vol. 25, December '95 (a Wiley pub.). I encourage readers of this
- newsgroup to look it up.]
-
- [I hope my excerpting hasn't done too much damage.]
-
- ----------------
-
- What does C++ offer no such facility? There are three main reasons:
-
- [1] Any such facility would have to take into account not only inheritance
- but also built-in types and operations on types not defined as members.
- ... Ordinary pointers meet the requirements for random-access iterators
- when they are used to point to elements of (built-in) arrays. That means
- we would need some way of saying that for any type T, T* is a random-
- access iterator, ... [or] forego the ability to use ... [template]
- functions on arrays. ...
-
- [2] The facility would offer little additional safety, if any. The main
- benefit would be that errors would be detected when a template function
- ... is called, rather than when code is generated for it... [this is]
- not enough to justify a whole new type-checking facility.
-
- [3] Even if such a facility existed ... that would still not guarantee
- safety. ... Specifying "the expected operations" can be messy and
- constraining; specifying "the expected semantics" can be surprisingly
- difficult. ...
-
- In general, we know of no way of expressing constraints on template
- parameters that wouldn't be either too cumbersome or too constraining.
- ...
-
- -----------------
-
- [In short, any such apparatus (in C++, at least) would be complicated,
- over-restrictive, and would fail to do the job required of it. Some
- incompatible successor to C++ might be designed with such an apparatus
- in mind, but today that's a research topic.]
-
- Nathan Myers
- ncm@cantrip.org http://www.cantrip.org/
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-